﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YasharEl.Infrastructure.ExceptionHandling.ServiceModel.FaultContacts;
using System.Collections.Specialized;
using YasharEl.Infrastructure.ObjectFactory;

namespace YasharEl.Infrastructure.ExceptionHandling.Configuration
{
    public partial class FaultContractExceptionHandlerConfig
    {
        public override IExceptionHandler CreateExceptionHandler(IDependencyResolver resolver)
        {
            NameValueCollection propertyMappings = new NameValueCollection();

            if (PropertyMappings != null && PropertyMappings.Count > 0)
            {
                foreach (PropertyMappingConfig propertyMapping in PropertyMappings)
                {
                    propertyMappings.Add(propertyMapping.Name, propertyMapping.Source);
                }
            }

            return new FaultContractExceptionHandler(
                FaultContractType,
                ExceptionMessage,
                ExceptionMessageResourceKey,
                resolver.Resolve<IMessageTranslator>(),
                propertyMappings
            );
        }
    }
}
